package com.juzipi.upload.controller;

import com.juzipi.demo.tools.json.ResultTool;
import com.juzipi.demo.utils.json.Result;
import com.juzipi.upload.pojo.ImageEntity;
import com.juzipi.upload.service.UploadService;
import com.juzipi.upload.utils.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.Map;

/**
 * @Author juzipi
 * @Date 2021/5/28 15:10
 * @Info
 */
//@Controller
//@RequestMapping
public class UploadController {

    @Autowired
    private UploadService uploadService;

    private final ResourceLoader resourceLoader;

    private final String path = "D:\\SpringBootLearning\\image";

    public UploadController(ResourceLoader resourceLoader){
        this.resourceLoader = resourceLoader;
    }

//    @RequestMapping("test")
//    public String toUpload(){
//        return "test";
//    }


//    @PostMapping("upload")
//    public String uploadFile(@RequestParam("file") MultipartFile file){
//        String localPath = "D:\\SpringBootLearning\\image\\";
//        if (FileUtils.upload(file,localPath)){
//            return "forward:/test";
//        }
//        return null;
//    }

//    @PostMapping("upload")
//    public Result uploadFile(@RequestParam("file") MultipartFile file){
//        String localPath = "D:\\SpringBootLearning\\image";
//        if (FileUtils.upload(file,localPath,file.getOriginalFilename())){
//            return ResultTool.successData(file.getOriginalFilename());
//        }
//        return ResultTool.fail();
//    }

//    @PostMapping("uploadImg")
//    @ResponseBody
//    public Map uploadImg(@RequestParam(value = "file")MultipartFile file){
//        return uploadService.insertFilePath(file);
//    }


//    @GetMapping("show")
//    public Result showImage(String fileName){
//        return ResultTool.successData(resourceLoader.getResource("file:" + path + fileName));
//    }


}
